#!/usr/bin/env python

from twisted.internet import defer, reactor

def run_later(seconds, function, *args, **kwargs):
    d = defer.Deferred()
    def fire():
        value = function(*args, **kwargs)
        print value
        d.callback(value)
    reactor.callLater(seconds, fire)
    return d

def print_stuff(message):
    print message
    
d = run_later(2, print_stuff, "hello")
d.addCallback(lambda ignored: run_later(3, print_stuff,'world'))
d.addCallback(lambda ignored: run_later(1, print_stuff, 'mio'))
run_later(3, print_stuff, 'Beutiful')
reactor.run()